package com.company.project.controller;
import com.company.project.annotation.OperLog;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.SysAuthList;
import com.company.project.service.SysAuthListService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by DLHTX on 2020/06/22.
 */
@RestController
@RequestMapping("/api/authList")
public class SysAuthListController {
    @Resource
    private SysAuthListService sysAuthListService;

    @PostMapping("/add")
    @OperLog(operModul = "权限管理-权限列表",operType = "添加",operDesc = "添加权限列表")
    public Result add(SysAuthList sysAuthList) {
        sysAuthListService.save(sysAuthList);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    @OperLog(operModul = "权限管理-权限列表",operType = "删除",operDesc = "删除权限列表")
    public Result delete(@RequestParam Integer id) {
        sysAuthListService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    @OperLog(operModul = "权限管理-权限列表",operType = "更新",operDesc = "更新权限列表")
    public Result update(SysAuthList sysAuthList) {
        sysAuthListService.update(sysAuthList);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        SysAuthList sysAuthList = sysAuthListService.findById(id);
        return ResultGenerator.genSuccessResult(sysAuthList);
    }

    @PostMapping("/getAuthList")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {

        List<SysAuthList> list = sysAuthListService.findAll();

        return ResultGenerator.genSuccessResult(list);
    }
}
